﻿using Sustainalytics.Auth.Claims;
using Sustainalytics.ClientDW.DataAccessLayer;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;

namespace Sustainalytics.Alerts.AlertsEngine
{
    public class FeatureUniversesCache : IFeatureUniversesCache
    {
        private ConcurrentDictionary<Guid, List<int>> _accountFeatureUnivDict;
        public FeatureUniversesCache(ConcurrentDictionary<Guid, List<int>> accountFeatureUnivDict)
        {
            _accountFeatureUnivDict = accountFeatureUnivDict;
          
        }
        public List<int> GetFeatureUniverses(Guid accountId, IUniversesRepository featureUnivRepo)
        {
            if (!_accountFeatureUnivDict.ContainsKey(accountId))
            {
                var featureUniv = featureUnivRepo.GetFeatureUniverse(accountId, AccountFeature.AlertControversies);
                if (featureUniv == null)
                {
                    _accountFeatureUnivDict[accountId] = new List<int>();
                }
                else
                {
                    _accountFeatureUnivDict[accountId] = featureUniv.UniverseIds;
                }
            }

            return _accountFeatureUnivDict[accountId];
        }

        public void CleanUp()
        {
            _accountFeatureUnivDict.Clear();
        }
    }
}
